package com.fast.fast.common.core.config.knife4j;

import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * Knife4j自动配置类
 *
 * @author lyf
 * @date 2022/01/01 00:00 周六
 **/
@RequiredArgsConstructor
@EnableSwagger2WebMvc
@EnableConfigurationProperties({Knife4jProperties.class})
@AutoConfiguration
public class Knife4jConfig {

    private final Knife4jProperties knife4jProperties;

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(
                        new ApiInfoBuilder()
                                .title(knife4jProperties.getTitle())
                                .description(knife4jProperties.getDescription())
                                .contact(new Contact(knife4jProperties.getAuthor(), knife4jProperties.getUrl(), knife4jProperties.getEmail()))
                                .version(knife4jProperties.getVersion())
                                .build())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

}
